package com.appkubes.fintech.restful.application.user.controller;

import com.appkubes.fintech.common.response.Response;
import com.appkubes.fintech.core.po.FintechUserJob;
import com.appkubes.fintech.restful.entity.vo.BaseUserKeyVO;
import com.appkubes.fintech.restful.application.user.entity.dto.CreditUserJobDTO;
import com.appkubes.fintech.restful.application.user.entity.vo.UserJobVO;
import com.appkubes.fintech.restful.application.user.service.UserJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@Slf4j
@Api(tags = "用户工作信息")
@RestController
@RequestMapping("/user/job")
public class UserJobController {

    @Resource
    UserJobService userJobService;

    @ApiOperation("添加用户工作信息")
    @PostMapping("/upsert")
    public Response saveUserJobInfo(@RequestBody @Valid UserJobVO userJobVO, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return Response.fail("参数检查失败");
        }

        Integer effectRow = userJobService.jobCertificate(userJobVO);
        return Response.success(effectRow);

    }

    @ApiOperation("查询用户工作信息")
    @GetMapping("/getJobInfo")
    public Response<CreditUserJobDTO> getUserJobInfo(@Valid BaseUserKeyVO userKeyVO, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return Response.fail("参数检查失败");
        }
        CreditUserJobDTO userJobDTO = new CreditUserJobDTO();
        FintechUserJob userJob = userJobService.getUserJobDao().selectByPrimaryKey(userKeyVO.getUserKey());
        if (userJob != null) {
            BeanUtils.copyProperties(userJob, userJobDTO);
        }
        return Response.success(userJobDTO);
    }
}
